package codetop.microsoft.T128;

import java.util.HashSet;
import java.util.Set;

/**
 * @Author: 18362
 * @Create: 2022-08-16 15:47:10 星期二
 */
class Solution {
    public int longestConsecutive(int[] nums) {
        Set<Integer> set = new HashSet<>();
        for (int num : nums)
            set.add(num);
        int maxLen = 0;
        for (int i=0; i<nums.length; ++i) {
            if (set.contains(nums[i]-1))
                continue;
            int len = 1;
            while (set.contains(nums[i]+len))
                len++;
            maxLen = Math.max(maxLen, len);
        }
        return maxLen;
    }
}
